package redis

import (
	"github.com/go-redis/redis/v8"
)

func GetClient() *redis.Client {
	return rdb
}

func Subscribe(channels ...string) <-chan *redis.Message {
	client := GetClient()
	sub := client.Subscribe(client.Context(), channels...)
	return sub.Channel()
}

func Publish(channel string, message interface{}) {
	client := GetClient()
	client.Publish(client.Context(), channel, message).Result()
}

// func getDeviceKey(deviceId string) string {
// 	return "goiot:device:" + deviceId
// }

// func getDevice(deviceId string) (*core.Device, bool) {
// 	device, ok := rdb.Load(getDeviceKey(deviceId))
// 	if ok {
// 		if device != nil {
// 			return device.(*core.Device), true
// 		}
// 		return nil, true
// 	}
// 	return nil, false
// }